package com.fenghongzhang.day006anim;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.view.View;
import android.view.animation.AlphaAnimation;
import android.view.animation.Animation;
import android.view.animation.AnimationSet;
import android.view.animation.AnimationUtils;
import android.view.animation.AnticipateInterpolator;
import android.view.animation.BounceInterpolator;
import android.view.animation.DecelerateInterpolator;
import android.view.animation.LinearInterpolator;
import android.view.animation.RotateAnimation;
import android.widget.Button;
import android.widget.ImageView;

public class MainActivity extends AppCompatActivity {
    private Button alpha;
    private ImageView img;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        alpha = (Button) findViewById(R.id.alpha);
        img = (ImageView) findViewById(R.id.img);


    }

    public void alpha(View view) {
        //1 xml方式
//        Animation animation = AnimationUtils.loadAnimation(this, R.anim.alpha);
//        img.startAnimation(animation);
        //2java
        AlphaAnimation alphaAnimation = new AlphaAnimation(1, 0);
        alphaAnimation.setDuration(2000);
        alphaAnimation.setFillAfter(true);
        alphaAnimation.setRepeatCount(1);//2次
        alphaAnimation.setRepeatMode(Animation.REVERSE);
        img.startAnimation(alphaAnimation);

    }

    public void rotate(View view) {
//        Animation animation = AnimationUtils.loadAnimation(this, R.anim.rotate);
//        img.startAnimation(animation);
        RotateAnimation rotateAnimation = new RotateAnimation(0, 360, 0.5f, 0.5f);
        rotateAnimation.setDuration(2000);
        rotateAnimation.setInterpolator(new BounceInterpolator());

//        rotateAnimation.setFillAfter(true);
        img.startAnimation(rotateAnimation);
    }

    public void scale(View view) {
        Animation animation = AnimationUtils.loadAnimation(this, R.anim.scale);
        img.startAnimation(animation);
    }

    public void trans(View view) {
        Animation animation = AnimationUtils.loadAnimation(this, R.anim.trans);
        img.startAnimation(animation);
    }

    public void zuhe(View view) {
//        Animation animation = AnimationUtils.loadAnimation(this, R.anim.zuhe);
//        img.startAnimation(animation);

        AnimationSet animationSet = new AnimationSet(true);
//        animationSet.setDuration(2000);
        Animation animation1 = AnimationUtils.loadAnimation(this, R.anim.rotate);
        Animation animation2 = AnimationUtils.loadAnimation(this, R.anim.trans);
        animationSet.addAnimation(animation1);
        animationSet.addAnimation(animation2);

        img.startAnimation(animationSet);



    }
}
